package com.example.joke.iv

import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.util.AttributeSet
import android.widget.ImageView

class SkewImageView(context: Context, attributeSet: AttributeSet? = null) : ImageView(context, attributeSet) {

    private var width: Int = 0
    private var height: Int = 0
    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        width = getWidth()
        height = getHeight()
    }

    override fun onDraw(canvas: Canvas?) {

        val path: Path = Path()
        path.moveTo(width.toFloat(), 0F)
        path.lineTo((width - height / Math.sqrt(3.0)).toFloat(), height.toFloat())
        path.lineTo(width.toFloat(), height.toFloat())
        path.close()
        canvas?.clipPath(path)

        super.onDraw(canvas)
    }

}